Beginning Visual Basic 2012 by Bryan Newsome

Beginning Visual Basic 2012 by Bryan Newsome

Author:Bryan Newsome
Language: eng
Format: epub, mobi
Publisher: Wrox
Published: 2012-09-09T16:00:00+00:00


'Add an empty string to the ListBox lstData.Items.Add(String.Empty) 'Demonstrates the use of the Using statement 'Allows acquisition, usage and disposal of the resource lstData.Items.Add("Computer Class Properties:") Using objMemory As New Computer lstData.Items.Add("FreeMemory = " & objMemory.FreeMemory) lstData.Items.Add("TotalMemory = " & objMemory.TotalMemory) End Using

Once again you add another blank line to the list box, and then you get to the final bit of code in this procedure. In this section of code we wanted to demonstrate the use of the Continue statement. The Continue statement is an efficient means of immediately transferring control to the next iteration of a loop. Instead of coding a lot of If … Then statements in a loop, you can merely test to see whether a condition is what you want and if it is not, you can call the Continue statement to pass control to the next iteration of a Do, For, or While loop.

Take a look at the code that you have here. First you declare a couple of variables and set their values. The first variable, strPassword, is declared and set to a password that contains uppercase and lowercase letters. The second variable, strLowerCaseLetters, is declared and set to an empty string so that the variable is initialized.

Next, you set up a For … Next loop to check each character in the strPassword variable. The If … Then statement uses the Like operator to compare a character in the password variable to a pattern of letters. If a match is found, the Like operator returns a value of True. However, you are using a negative comparison here, because you have included the Not keyword in the If … Then statement, so if the character in the password variable is not like one of the letters in the pattern, [a-z], you execute the next statement, which is the Continue statement.

If the character in the password variable is a lowercase letter, then you concatenate the character to the strLowerCaseLetters variable, which is why you needed to initialize this variable to an empty string when you declared it.

Finally, after all lowercase letters have been extracted from the password variable, you display the results of the strLowerCaseLetters variable in the list box on your form:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.